package com.gcxy.controller;

import com.gcxy.core.R;
import com.gcxy.dto.user.UserLoginDTO;
import com.gcxy.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 登录模块控制器
 *
 * @author pep7chiao
 * @date 2024/7/7
 */
@Api(tags = "登录管理")
@RestController
public class LoginController {
    @Resource
    private UserService userService;

    @ApiOperation(value = "登录后返回token")
    @PostMapping("/login")
    public R login(@RequestBody UserLoginDTO userLoginDTO, HttpServletRequest request) {
        return userService.login(userLoginDTO.getUsername(), userLoginDTO.getPassword(), request);
    }

    @ApiOperation(value = "退出登录")
    @PostMapping("/logout")
    public R logout(HttpServletRequest request) {
        return userService.logout(request);
    }
}
